package cn.ffcs.uec.organization.component;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Div;
import org.zkoss.zul.Treeitem;

import cn.ffcs.uec.organization.component.bean.UecOrganizationTreeboxExtBean;
import cn.ffcs.uec.organization.constant.UecOrganizationConstant;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.zkplus.zul.tree.node.impl.TreeNodeImpl;
import lombok.Getter;
import lombok.Setter;

@Controller
@Scope("prototype")
public class UecOrganizationTreeboxExt extends Div implements IdSpace {
	
	private static final long serialVersionUID = 8456854085652207340L;
	/**
	 * .zul
	 */
	private final String zul = "/pages_nmg/uec_organization/comp/uec_organization_treebox_ext.zul";
	
	private UecOrganizationTreeboxExtBean bean = new UecOrganizationTreeboxExtBean();
	
	/**
	 * 选择的组织
	 */
	private OrganizationRelationVo organizationRelationVo;
	
	/**
	 * 选中的组织TreeItem
	 */
	@SuppressWarnings("unused")
	private Treeitem selectedTreeitem;
	
	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;
	
	public UecOrganizationTreeboxExt() {
		Executions.createComponents(this.zul, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');
	}
	/*
	 * 点击时选择树
	 */
	public void onSelect$uecOrganizationRelationTree() {
		selectedTreeitem = this.bean.getUecOrganizationRelationTree()
				.getSelectedItem();
		organizationRelationVo = (OrganizationRelationVo) ((TreeNodeImpl<?>) this.bean
				.getUecOrganizationRelationTree().getSelectedItem().getValue())
				.getEntity();
		if (null != organizationRelationVo
				&& null != organizationRelationVo.getOrg()) {
			Events.postEvent(
					UecOrganizationConstant.ON_SELECT_ORGREATION_TREE_REQUEST,
					this, organizationRelationVo);
		}
	}

}

